package org.september.pisces.sms.controller;

import org.september.core.exception.BusinessException;
import org.september.pisces.sms.entity.SmsSentLog;
import org.september.pisces.sms.service.SmsTmplService;
import org.september.pisces.user.permission.service.OperationLogService;
import org.september.simpleweb.controller.BaseController;
import org.september.simpleweb.model.ResponseVo;
import org.september.smartdao.model.Page;
import org.september.smartdao.model.ParamMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 短信模板管理
 */
@Controller
public class SmsSentLogController extends BaseController {

    @Autowired
    private SmsTmplService smsService;
    
    @Autowired
    private OperationLogService operationLogService;

    @RequestMapping(value = List_Page)
    public ModelAndView sentLogList() throws Exception {
        ModelAndView mv = new ModelAndView();
        return mv;
    }

    @ResponseBody
    @RequestMapping(value = List_Data)
    public ResponseVo<Page<SmsSentLog>> listSentLogData(Page<SmsSentLog> page, SmsSentLog vo) throws Exception {
        ParamMap pm = new ParamMap(vo);
        page = smsService.getCommonDao().findPageByParams(SmsSentLog.class, page, "PiscesSms.listSentLog", pm);
        return ResponseVo.<Page<SmsSentLog>>BUILDER().setData(page).setCode(ResponseVo.BUSINESS_CODE.SUCCESS);
    }

    @ResponseBody
    @RequestMapping(value = Delete_Action)
    public ResponseVo<String> delete(Long id) throws Exception {
    	SmsSentLog po = smsService.getCommonDao().get(SmsSentLog.class, id);
        if (po == null) {
            throw new BusinessException("数据不存在或已删除");
        }
        smsService.delete(po);
        operationLogService.addLog("删除了短信发送记录【" + po.getMobile() +"," + po.getContent()+ "】");
        return ResponseVo.<String>BUILDER().setCode(ResponseVo.BUSINESS_CODE.SUCCESS);
    }
    
    private static final String Mapping_Prefix = "/pisces/sms/log";
	public static final String List_Page = Mapping_Prefix+"/sentLogList";
	public static final String List_Data = Mapping_Prefix+"/listSentLogData";
	public static final String Delete_Action = Mapping_Prefix+"/delete";
}
